#!/bin/sh
# This shell script used to cross compile the linux kernel for FL2440
# Before excute this shell script, please download the source code packet
# to here first.

KERNEL_SRC=linux-2.6.33
IMAGE_NAME=uImage-s3c.gz
INST_PATH=~/winxp/images
PATCH_FILE=./patch/fl2440-${KERNEL_SRC}.patch

if [ ! -f ${KERNEL_SRC}/.config ] ; then
   if [ -f ${KERNEL_SRC}.tar.bz2 -a -f $PATCH_FILE ] ; then
        echo "==================================================="
        echo "+         Decompress linux kernel now...          +"
        echo "==================================================="
        rm -rf ${KERNEL_SRC}
        tar -xjf ${KERNEL_SRC}.tar.bz2 

        echo "==================================================="
        echo "+                 Patching now...                 +"
        echo "==================================================="
        patch -p0 < $PATCH_FILE
   else
        echo "==============================================================="
        echo "+    ERROR: Missing Linux Kernel Source Code Packet!          +"
        echo "+ Plese download ${KERNEL_SRC}.tar.bz2 to here and try again!  +"
        echo "==============================================================="
        exit;
   fi
fi

echo "==================================================="
echo "+                 Building now...                 +"
echo "==================================================="

cd ${KERNEL_SRC} 
make 

echo "==================================================="
echo "+     Generate uImage and install now...          +"
echo "==================================================="
rm -f ${IMAGE_NAME}
cp arch/arm/boot/zImage . -f
mkimage -A arm -O linux -T kernel -C none -a 30008000 -e 30008040 -n "Linux Kernel" -d zImage ${IMAGE_NAME}
rm -f zImage
cp ${IMAGE_NAME} ${INST_PATH}

